package com.fjrcloud.service;

import com.fjrcloud.dao.HousingDecorateIntoNewDao;
import com.fjrcloud.dao.HousingDecorateLevelDao;
import com.fjrcloud.entity.HousingDecorateIntoNew;
import com.fjrcloud.entity.HousingDecorateLevel;
import com.fjrcloud.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * Created by shengjian.lin on 17-1-18.
 */
@Service
public class HousingDecorateService {

    @Autowired
    private HousingDecorateLevelDao decorateLevelDao;
    @Autowired
    private HousingDecorateIntoNewDao decorateIntoNewDao;

    public HousingDecorateLevel saveDecorateLevel(HousingDecorateLevel decorateLevel){

        decorateLevel.setCreateTime(System.currentTimeMillis());

        return decorateLevelDao.save(decorateLevel);
    }
    public HousingDecorateLevel getDecorateLevel(Integer id){
        return decorateLevelDao.findOne(id);
    }
    public void delDecorateLevel(Integer id){
        decorateLevelDao.delete(id);
    }

    public Page<HousingDecorateLevel> listDecorateLevel(Integer pageNum, Integer pageSize){

        pageNum = PageUtils.checkPageNum(pageNum);
        pageSize = PageUtils.checkPageSize(pageSize);
        PageRequest pageRequest = new PageRequest(pageNum, pageSize);

        return decorateLevelDao.findByValidOrderByCreateTimeAsc(true,pageRequest);
    }

    public HousingDecorateIntoNew saveDecorateIntoNew(HousingDecorateIntoNew intoNew){

        intoNew.setCreateTime(System.currentTimeMillis());

        return decorateIntoNewDao.save(intoNew);
    }
    public HousingDecorateIntoNew getDecorateIntoNew(Integer id){
        return decorateIntoNewDao.findOne(id);
    }
    public void delDecorateIntoNew(Integer id){
        decorateIntoNewDao.delete(id);
    }

    public Page<HousingDecorateIntoNew> listDecorateIntoNew(Integer pageNum, Integer pageSize){

        pageNum = PageUtils.checkPageNum(pageNum);
        pageSize = PageUtils.checkPageSize(pageSize);
        PageRequest pageRequest = new PageRequest(pageNum, pageSize);

        return decorateIntoNewDao.findByValidOrderByCreateTimeAsc(true,pageRequest);
    }
}
